package com.mooer.http;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.util.Log;

import com.mooer.bean.Comment;
import com.mooer.bean.GlodenManual;
import com.mooer.bean.SearchLocation;
import com.mooer.bean.Shop;
import com.mooer.bean.ShopActivity;
import com.mooer.bean.ShopAddress;
import com.mooer.bean.SignAccount;
import com.mooer.bean.SignInfo;
import com.mooer.bean.TreeNode;
import com.mooer.bean.User;
import com.mooer.cache.PicCache;
import com.mooer.domain.ResBean;
import com.mooer.enums.ResultStatusEnum;
import com.mooer.exception.SVException;
import com.mooer.utils.ResponseResultBean;
import com.mooer.utils.UtilTools;

/**
 * Http 入口工具类，调用本类中的方法进行Http交互
 * 
 * @author pengfei.xu
 * @version V1.0 创建时间：2011-4-28 下午05:31:29
 */
public class HttpUtils {
	public final static String TAG = "HttpUtils";

	public static final int CODE_OK = 200;

	public static HttpConnectionImpl httpConnection = null;

	private static HttpConnection getHttpConnection() {
		if (httpConnection == null)
			httpConnection = new HttpConnectionImpl();
		return httpConnection;
	}

	public static ResBean getStream(String url) {
		return getHttpConnection().getStream(url, null);
	}

	/*
	 * 下载图片
	 */
	public static Bitmap downloadBitmap(String url) {
		Log.i(TAG, "获取图片:" + url);
		Bitmap bitmap = getHttpConnection().downloadBitmap(url);
		return bitmap;
	}

	/*
	 * 下载图片
	 */
	public static Bitmap downloadBitmap(String businessId, String url) {
		Bitmap bitmap = PicCache.get(businessId);
		if (bitmap == null) {
			Log.i(TAG, "获取图片:" + url);
			bitmap = getHttpConnection().downloadBitmap(url);
			if (bitmap != null)
				PicCache.put(businessId, bitmap);
		}
		return bitmap;
	}

	/*
	 * 下载图片
	 */
	public static Bitmap downloadBitmap(String businessId, String url,
			int timeOut) {
		Bitmap bitmap = PicCache.get(businessId);
		if (bitmap == null) {
			bitmap = getHttpConnection().downloadBitmap(url, timeOut);
			if (bitmap != null)
				PicCache.put(businessId, bitmap);
		}
		return bitmap;
	}

	/**
	 * 用户登录
	 * 
	 * @param account
	 * @param password
	 * @return
	 * @throws UnsupportedEncodingException
	 * @throws SVException
	 */
	public static User login(String account, String password)
			throws SVException {
		User user = null;
		// 参数防止注入或者污染，需要经过编码
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=login" + "&username=" + UtilTools.encodeURL(account)
				+ "&password=" + UtilTools.encodeURL(password);
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取用户服务");
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "用户登录");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {

			Log.d(TAG, "转换用户数据");
			Log.d(TAG, bean.getData().optJSONObject(0).toString());
			JSONObject jsonObject = bean.getData().optJSONObject(0);
			user = new User();
			user.setId(jsonObject.optInt("user_id"));
			user.setUserName(jsonObject.optString("user_name"));
			user.setSex(jsonObject.optBoolean("sex"));
			user.setPhone(jsonObject.optString("mobile"));
			user.setPhoto(jsonObject.optString("user_logo"));
		}
		return user;
	}

	/**
	 * 注销登陆的用户
	 * 
	 * @return
	 * @throws SVException
	 */
	public static void logout() throws SVException {
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=loginout";
		HashMap<String, String> headers = new HashMap<String, String>();
		try {
			Log.d(TAG, "用户注销");
			getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.d(TAG, "用户注销登陆发生错误");
			throw e;
		}
	}

	/**
	 * 用户注册信息提交，成功是发送信息到手机
	 * 
	 * @return
	 * @throws SVException
	 * @throws JSONException 
	 */
	public static long register_step1(User user) throws SVException, JSONException {
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=register_step1" + "&phone="
				+ UtilTools.encodeURL(user.getPhone()) + "&nick_name="
				+ UtilTools.encodeURL(user.getUserName()) + "&password="
				+ UtilTools.encodeURL(user.getPassword()) + "&sex="
				+ (user.isSex() ? "1" : "0");
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "用户注册");
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.d(TAG, "用户注册发生错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			JSONObject object = bean.getData().getJSONObject(0);
			if(object.getBoolean("success")){
				return object.getLong("id");
			}
		}
		return -1;
	}

	/**
	 * 注册用户短信确认
	 * 
	 * @param uid
	 * @param smsCode
	 * @return
	 * @throws SVException
	 * @throws JSONException 
	 */
	public static boolean register_step2(long uid, String smsCode)
			throws SVException, JSONException {
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=register_step2" + "&code="
				+ UtilTools.encodeURL(smsCode) + "&id=" + uid;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "用户注册短信验证");
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.d(TAG, "用户注册短信验证发生错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			JSONObject object = bean.getData().getJSONObject(0);
			return object.getBoolean("success");
		}
		return false;
	}

	/**
	 * 获取附近商家目录
	 * 
	 * @param search
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<TreeNode> fetchNearShopCategoryList(
			SearchLocation search, int limitStart, int limit)
			throws SVException {
		List<TreeNode> categories = new ArrayList<TreeNode>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=list_shoplist_by_category" + "&longitude="
				+ search.getLongitude() + "&latitude=" + search.getLatitude()
				+ "&radius=" + search.getRadius() + "&category="
				+ search.getCategory() + "&search="
				+ UtilTools.encodeURL(search.getSearch()) + "&limitstart="
				+ limitStart + "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取附近商家目录");
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取附近商家目录错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					TreeNode node = new TreeNode();
					node.setId(object.getInt("category_id"));
					node.setName(object.getString("category_name"));
					node.setParentId(object.getInt("parentid"));
					categories.add(node);
				}
			} catch (JSONException e) {
				String errMsg = "获取附近商家目录获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return categories;
	}

	/**
	 * 获取附近商家列表
	 * 
	 * @param search
	 * @param limitStart
	 * @param limit
	 *            0表示不限制
	 * @return
	 * @throws SVException
	 */
	public static List<Shop> fetchNearShopList(SearchLocation search,
			int limitStart, int limit) throws SVException {
		List<Shop> shops = new ArrayList<Shop>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=list_shopitem" + "&longitude=" + search.getLongitude()
				+ "&latitude=" + search.getLatitude() + "&radius="
				+ search.getRadius() + "&category=" + search.getCategory()
				+ "&region=" + search.getRegion() + "&limitstart=" + limitStart
				+ "&limit=" + limit + "&userid=24222";
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取附近商家列表 : " + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取附近商家列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					Shop shop = new Shop();
					shop.setId(object.getInt("shop_id"));
					shop.setName(object.getString("shop_name"));
					shop.setLogo(object.optString("shop_logo"));
					shop.setRating(object.getDouble("rating"));
					shop.setDistance(object.optDouble("distance"));
					shop.setAvgConsumption(object.optDouble("avg_consumption"));
					shop.setHasCoupon(object.optBoolean("is_coupon", false));
					shop.setServices(object.optString("services"));
					shop.setCategoryId(object.optInt("category_id"));
					shop.setCategoryName(object.optString("category_name"));
					shop.setPhone(object.optString("telephone"));
					ShopAddress addr = new ShopAddress();
					addr.setAreaCode(object.optString("regision_id"));
					addr.setAreaName(object.optString("regision_name"));
					addr.setAddress1(object.optString("address"));
					addr.setLatitude(object.optDouble("lat"));
					addr.setLongitude(object.optDouble("lng"));
					shop.setAddress(addr);
					shops.add(shop);
				}
			} catch (JSONException e) {
				String errMsg = "获取附近商家列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shops;
	}

	/**
	 * 根据条件查询商家的目录和地区信息
	 * 
	 * @param search
	 * @return
	 * @throws SVException
	 */
	public static Map<String, List<TreeNode>> fetchCategoryAndRegionTree(
			SearchLocation search) throws SVException {
		Map<String, List<TreeNode>> map = new HashMap<String, List<TreeNode>>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_list_and_categroy" + "&longitude="
				+ search.getLongitude() + "&latitude=" + search.getLatitude()
				+ "&radius=" + search.getRadius() + "&category="
				+ search.getCategory() + "&search="
				+ UtilTools.encodeURL(search.getSearch());
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "根据条件查询商家的目录和地区信息:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "根据条件查询商家的目录和地区信息 错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				JSONObject categoryAndRegion = bean.getData().getJSONObject(0);
				JSONArray cats = categoryAndRegion.getJSONArray("category");
				JSONArray regs = categoryAndRegion.getJSONArray("region");
				if (cats != null && cats.length() > 0) {
					List<TreeNode> catTree = new ArrayList<TreeNode>();
					for (int i = 0; i < cats.length(); i++) {
						JSONObject object = cats.getJSONObject(i);
						TreeNode node = new TreeNode();
						node.setId(object.getInt("category_id"));
						node.setName(object.getString("category_name"));
						node.setParentId(object.getInt("category_parentid"));
						catTree.add(node);
					}
					map.put("category", catTree);
				}
				if (regs != null && regs.length() > 0) {
					List<TreeNode> regTree = new ArrayList<TreeNode>();
					for (int i = 0; i < regs.length(); i++) {
						JSONObject object = regs.getJSONObject(i);
						TreeNode node = new TreeNode();
						node.setId(object.getInt("region_id"));
						node.setName(object.getString("region_name"));
						node.setParentId(object.getInt("region_parent_id"));
						regTree.add(node);
					}
					map.put("region", regTree);
				}
			} catch (JSONException e) {
				String errMsg = "根据条件查询商家的目录和地区信息 获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return map;
	}

	/**
	 * 获取商家详细信息
	 * 
	 * @param shopId
	 * @return
	 * @throws SVException
	 */
	public static Shop fetchShopDetail(int shopId) throws SVException {
		Shop shop = null;
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=search_shopinfo_by_id" + "&shop=" + shopId;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取商家详细信息:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取商家详细信息错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				JSONObject jsonObject = bean.getData().optJSONObject(0);
				shop = new Shop();
				shop.setId(jsonObject.getInt("shop_id"));
				String branch = UtilTools.isEmpty(jsonObject
						.optString("shop_branch")) ? "" : " ("
						+ jsonObject.optString("shop_branch") + ") ";
				shop.setName(jsonObject.getString("shop_name") + branch);
				shop.setLogo(jsonObject.optString("logo"));
				shop.setPhone(jsonObject.optString("telephone"));
				ShopAddress address = new ShopAddress();
				address.setAddress1(jsonObject.optString("address"));
				address.setLongitude(jsonObject.optDouble("lng"));
				address.setLatitude(jsonObject.optDouble("lat"));
				address.setRegionName(jsonObject.optString("region"));
				shop.setAddress(address);
				shop.setCategoryId(jsonObject.optInt("category_id"));
				shop.setCategoryName(jsonObject.optString("categroy_name"));
				shop.setPromotionId(jsonObject.optInt("promotion_id"));
				shop.setPromotionTitle(jsonObject.optString("promotion_title"));
				shop.setPromotionContent(jsonObject
						.optString("promotion_content"));
				shop.setPromotionHelp(jsonObject.optString("promotion_help"));
				shop.setCouponDateline(jsonObject.optString("endtime"));
			} catch (JSONException e) {
				String errMsg = "用户数据获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shop;
	}

	/**
	 * 获取商家相册图片
	 * 
	 * @param shopId
	 * @return
	 * @throws SVException
	 */
	public static ArrayList<String> fetchShopGallery(int shopId)
			throws SVException {
		ArrayList<String> photos = new ArrayList<String>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_pic_shop_id" + "&shop_id=" + shopId;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取商家相册图片 : " + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取商家相册图片错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					// JSONObject object = bean.getData().getJSONObject(i);
					String photo = bean.getData().getString(i);
					photos.add(photo);
				}
			} catch (JSONException e) {
				String errMsg = "获取附近商家列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return photos;
	}

	/**
	 * 根据搜索获取商家列表
	 * 
	 * @param search
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<Shop> fetchShopListByCategory(SearchLocation search,
			int limitStart, int limit) throws SVException {
		List<Shop> shops = new ArrayList<Shop>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=list_shopitem_by_key" + "&lng="
				+ search.getLongitude() + "&lat=" + search.getLatitude()
				+ "&radius=" + search.getRadius() + "&category="
				+ search.getCategory() + "&region=" + search.getRegion()
				+ "&search=" + UtilTools.encodeURL(search.getSearch())
				+ "&limitstart=" + limitStart + "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "根据目录获取商家列表:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "根据目录获取商家列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					Shop shop = new Shop();
					shop.setId(object.getInt("shop_id"));
					String branch = UtilTools.isEmpty(object
							.optString("shop_branch")) ? "" : " ("
							+ object.optString("shop_branch") + ") ";
					shop.setName(object.getString("shop_name") + branch);
					shop.setLogo(object.optString("logo"));
					shop.setRating(object.getDouble("rating"));
					shop.setDistance(object.optDouble("distance"));
					shop.setAvgConsumption(object.optDouble("avg_consumption"));
					shop.setHasCoupon(object.optBoolean("is_coupon", false));
					shop.setServices(object.optString("services"));
					shop.setCategoryId(object.optInt("category_id"));
					shop.setCategoryName(object.optString("category_name"));
					ShopAddress addr = new ShopAddress();
					addr.setAreaCode(object.optString("region_id"));
					addr.setAreaName(object.optString("CBD"));
					addr.setLatitude(object.optDouble("lat"));
					addr.setLongitude(object.optDouble("lng"));
					shop.setAddress(addr);
					shops.add(shop);
				}
			} catch (JSONException e) {
				String errMsg = "根据目录获取商家列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shops;
	}

	/**
	 * 获取附近签到商家列表信息
	 * 
	 * @param search
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<Shop> fetchNearShopListWithSign(SearchLocation search,
			int limitStart, int limit) throws SVException {
		List<Shop> shops = new ArrayList<Shop>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=list_shopitem_of_qiandao" + "&longitude="
				+ search.getLongitude() + "&latitude=" + search.getLatitude()
				+ "&radius=" + search.getRadius() + "&search="
				+ UtilTools.encodeURL(search.getSearch()) + "&limitstart="
				+ limitStart + "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取附近签到商家列表信息");
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取附近签到商家列表信息错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					Shop shop = new Shop();
					shop.setId(object.getInt("shopid"));
					/*
					 * String branch = UtilTools.isEmpty(object
					 * .optString("shop_branch")) ? "" : " (" +
					 * object.optString("shop_branch") + ") ";
					 */
					shop.setName(object.getString("shop_name"));
					shop.setLogo(object.optString("shoplogo"));
					shop.setRating(object.getDouble("rating"));
					shop.setDistance(object.optDouble("distance"));
					shop.setAvgConsumption(object.optDouble("avg_consumption"));
					// shop.setHasCoupon(object.optBoolean("is_coupon", false));
					shop.setServices(object.optString("services"));
					shop.setCategoryId(object.optInt("category_id"));

					shops.add(shop);
				}
			} catch (JSONException e) {
				String errMsg = "附近签到商家列表信息获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shops;
	}

	/**
	 * 获取商家的签到信息列表
	 * 
	 * @param shopId
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<SignInfo> fetchSignInfoListByShop(int shopId,
			int limitStart, int limit) throws SVException {
		List<SignInfo> signs = new ArrayList<SignInfo>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_qiandao_info" + "&shop=" + shopId + "&limitstart="
				+ limitStart + "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取商家的签到信息列表:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取商家的签到信息列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					SignInfo sign = new SignInfo();
					sign.setId(object.getInt("qiandao_id"));
					Shop shop = new Shop();
					shop.setId(object.getInt("shopid"));
					shop.setName(object.getString("shopname"));
					sign.setShop(shop);
					User user = new User();
					user.setId(object.getInt("uid"));
					user.setUserName(object.getString("username"));
					user.setPhoto(object.optString("user_logo"));
					sign.setUser(user);
					sign.setComment(object.optString("comment"));
					sign.setDate(object.optString("sign_date"));
					signs.add(sign);
				}
			} catch (JSONException e) {
				String errMsg = "获取商家的签到信息列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return signs;
	}

	/**
	 * 签到商家
	 * 
	 * @param shopId
	 * @param longitude
	 * @param latitude
	 * @return
	 * @throws SVException
	 */
	public static int doSignShop(int shopId, int userId, double longitude,
			double latitude, String content) throws SVException {
		int count = 0;
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=set_qiandao" + "&shopid=" + shopId + "&uid=" + userId
				+ "&lng=" + longitude + "&lat=" + latitude + "&content="
				+ UtilTools.encodeURL(content);
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "签到商家:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "签到商家错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				JSONObject object = bean.getData().optJSONObject(0);
				if (object != null) {
					count = object.getInt("times");
				}
			} catch (JSONException e) {
				String errMsg = "最新金品手册数据获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return count;
	}

	/**
	 * 获取签到账户信息
	 * 
	 * @param userId
	 * @return
	 * @throws SVException
	 */
	public static SignAccount fetchAccountInfo(int userId) throws SVException {
		SignAccount account = null;
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_user_info" + "&uid=" + userId;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取签到账户信息:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取签到账户信息错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				JSONObject object = bean.getData().optJSONObject(0);
				if (object != null) {
					account = new SignAccount();
					User user = new User();
					user.setId(object.getInt("user_id"));
					user.setUserName(object.getString("nick_name"));
					user.setPhoto(object.optString("user_logo"));
					account.setUser(user);
					account.setCatFood(object.getInt("cat_food"));
					account.setAgeByWeek(object.getInt("age_week"));
					account.setGroupId(object.getInt("groupid"));
					account.setGroupName(object.getString("groupname"));
					account.setSignCount(object.getInt("sign_num"));
					account.setGrade(object.getString("age_week"));
				}
			} catch (JSONException e) {
				String errMsg = "用户数据获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return account;
	}

	/**
	 * 获取我的签到商家历史记录列表
	 * 
	 * @param userId
	 * @return
	 * @throws SVException
	 */
	public static List<SignInfo> fetchHisSignedShopListByUser(int userId,
			int limitStart, int limit) throws SVException {
		List<SignInfo> signedShops = new ArrayList<SignInfo>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_my_qiandao_info" + "&uid=" + userId
				+ "&limitstart=" + limitStart + "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取我的签到商家历史记录列表:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取我的签到商家历史记录列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					SignInfo signedShop = new SignInfo();
					Shop shop = new Shop();
					shop.setId(object.getInt("shop_id"));
					/*
					 * String branch = UtilTools.isEmpty(object
					 * .optString("shop_branch")) ? "" : " (" +
					 * object.optString("shop_branch") + ") ";
					 */
					shop.setName(object.getString("shop_name"));
					shop.setCategoryId(object.optInt("category_id"));
					signedShop.setShop(shop);
					User user = new User();
					// user.setId(object.optInt(""));
					// user.setPhoto(object.optString(""));
					// user.setUserName(object.optString(""));
					signedShop.setUser(user);
					signedShop.setDate(object.getString("sign_date"));
					signedShops.add(signedShop);
				}
			} catch (JSONException e) {
				String errMsg = "获取我的签到商家历史记录列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return signedShops;
	}

	/**
	 * 获取附近签到评论列表
	 * 
	 * @param search
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<SignInfo> fetchNearSignedInfoList(SearchLocation search,
			int limitStart, int limit) throws SVException {
		List<SignInfo> signInfos = new ArrayList<SignInfo>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_all_qiandao_by_all_user" + "&longitude="
				+ search.getLongitude() + "&latitude=" + search.getLatitude()
				+ "&radius=" + search.getRadius() + "&limitstart=" + limitStart
				+ "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取附近签到评论列表:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取附近签到评论列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					SignInfo signedShop = new SignInfo();
					signedShop.setId(object.getInt("qiandao_id"));
					Shop shop = new Shop();
					shop.setId(object.getInt("shop_id"));
					shop.setName(object.getString("shop_name"));
					signedShop.setShop(shop);
					signedShop.setDate(object.getString("qiandao_date"));
					User user = new User();
					user.setId(object.optInt("user_id"));
					user.setPhoto(object.optString("user_logo"));
					user.setUserName(object.optString("user_name"));
					signedShop.setUser(user);
					signInfos.add(signedShop);
				}
			} catch (JSONException e) {
				String errMsg = "附近签到评论列表错误获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return signInfos;
	}

	/**
	 * 获取最近添加的商户列表
	 * 
	 * @param search
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<Shop> fetchLatestShopList(SearchLocation search,
			int limitStart, int limit) throws SVException {
		List<Shop> shops = new ArrayList<Shop>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_nearest_add_shop" + "&category="
				+ search.getCategory() + "&limitstart=" + limitStart
				+ "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取最近添加的商户列表");
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取最近添加的商户列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					Shop shop = new Shop();
					shop.setId(object.getInt("shop_id"));
					String branch = UtilTools.isEmpty(object
							.optString("shop_branch")) ? "" : " ("
							+ object.optString("shop_branch") + ") ";
					shop.setName(object.getString("shop_name") + branch);
					shop.setLogo(object.optString("shoplogo"));
					// shop.setRating(object.getDouble("rating"));
					// shop.setDistance(object.optDouble("distance"));
					shop.setAvgConsumption(object.optDouble("avg_consumption"));
					shop.setHasCoupon(object.optBoolean("is_coupon", false));
					shop.setServices(object.optString("services"));
					shop.setCategoryId(object.optInt("category_id"));
					shop.setCategoryName(object.optString("category_name"));
					ShopAddress addr = new ShopAddress();
					addr.setAreaCode(object.optString("region_id"));
					addr.setAreaName(object.optString("region_name"));
					addr.setLatitude(object.optDouble("lat"));
					addr.setLongitude(object.optDouble("lng"));
					shop.setAddress(addr);
					shops.add(shop);
				}
			} catch (JSONException e) {
				String errMsg = "最近添加的商户列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shops;
	}

	/**
	 * 获取最近添加的优惠商户列表
	 * 
	 * @param type
	 * @param search
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<Shop> fetchShopUpdateInfo(int type,
			SearchLocation search, int limitStart, int limit)
			throws SVException {
		List<Shop> shops = new ArrayList<Shop>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_nearest_preinfo" + "&limitstart=" + limitStart
				+ "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取最近添加的优惠商户列表");
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取最近添加的优惠商户列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					Shop shop = new Shop();
					shop.setId(object.getInt("shop_id"));
					// String branch = UtilTools.isEmpty(object
					// .optString("shop_branch")) ? "" : " ("
					// + object.optString("shop_branch") + ") ";
					shop.setName(object.getString("shop_name"));
					shop.setLogo(object.optString("shop_logo"));
					shop.setRating(object.getDouble("rating"));
					// shop.setDistance(object.optDouble("distance"));
					shop.setAvgConsumption(object.optDouble("avg_consumption"));
					shop.setHasCoupon(true);
					shop.setServices(object.optString("services"));
					shop.setCategoryId(object.optInt("category_id"));
					shop.setCategoryName(object.optString("category_name"));
					ShopAddress addr = new ShopAddress();
					addr.setAreaCode(object.optString("region_id"));
					addr.setAreaName(object.optString("region_name"));
					addr.setLatitude(object.optDouble("lat"));
					addr.setLongitude(object.optDouble("lng"));
					shop.setAddress(addr);
					shops.add(shop);
				}
			} catch (JSONException e) {
				String errMsg = "最近添加的优惠商户列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shops;
	}

	/**
	 * 获取最新金品手册
	 * 
	 * @param version
	 * @return
	 * @throws SVException
	 */
	public static GlodenManual fetchLatestGlodenManual(String version)
			throws SVException {
		GlodenManual manual = null;
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_nearest_jinpin" + "&version="
				+ UtilTools.encodeURL(version);
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取最新金品手册:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取最新金品手册错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				JSONObject object = bean.getData().optJSONObject(0);
				if (object != null) {
					manual = new GlodenManual();
					manual.setId(object.getInt("id"));
					manual.setTopImage(object.optString("img"));
					manual.setContent(object.getString("content"));
					Log.i(TAG, manual.getContent());
				}
			} catch (JSONException e) {
				String errMsg = "最新金品手册数据获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return manual;
	}

	/**
	 * 获取活动列表
	 * 
	 * @param type
	 *            -1 往期, 0 当期, 1 预告
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<ShopActivity> fetchShopActivityList(int type,
			int limitStart, int limit) throws SVException {
		List<ShopActivity> shopActivities = new ArrayList<ShopActivity>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_activity_list" + "&type1=" + type + "&limitstart="
				+ limitStart + "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取活动列表:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取活动列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					ShopActivity shopActivity = new ShopActivity();
					shopActivity.setId(object.getInt("event_id"));
					shopActivity.setType(object.getInt("type"));
					shopActivity.setSummary(object.getString("title"));
					shopActivity.setSmallImage(object.optString("image"));
					shopActivity.setReply(object.optInt("reply"));
					shopActivity.setJoin(object.optInt("join"));
					shopActivity.setContent(object.optString("text"));
					shopActivity.setDate(object.optString("end"));
					shopActivities.add(shopActivity);
				}
			} catch (JSONException e) {
				String errMsg = "获取活动列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shopActivities;
	}

	/**
	 * 获取活动详细信息
	 * 
	 * @param shopActivityId
	 * @param type
	 *            -1 往期 0 当期 1 预告
	 * @return
	 * @throws SVException
	 */
	public static ShopActivity fetchShopActivityDetail(int shopActivityId,
			int type) throws SVException {
		ShopActivity shopActivity = null;
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_activity_content" + "&tid=" + shopActivityId;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取活动详细信息");
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取活动详细信息错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				JSONObject object = bean.getData().optJSONObject(0);
				if (object != null) {
					shopActivity = new ShopActivity();
					shopActivity.setId(object.getInt("tid"));
					shopActivity.setSubject(object.getString("title"));
					shopActivity.setBigImage(object.optString("image"));
					shopActivity.setContent(object.getString("text"));
				}
			} catch (JSONException e) {
				String errMsg = "活动详细信息获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shopActivity;
	}

	/**
	 * 获取此活动评论列表
	 * 
	 * @param shopActivityId
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<Comment> fetchShopActivityCommentList(
			int shopActivityId, int limitStart, int limit) throws SVException {
		List<Comment> actComments = new ArrayList<Comment>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_activity_replys" + "&tid=" + shopActivityId
				+ "&limitstart=" + limitStart + "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取此活动评论列表:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取此活动评论列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					Comment comment = new Comment();
					// comment.setId(object.getInt("event_id"));
					User user = new User();
					user.setId(object.getInt("userid"));
					user.setUserName(object.optString("username"));
					user.setPhoto(object.optString("user_logo"));
					comment.setUser(user);
					comment.setContent(object.optString("comment"));
					comment.setDate(object.optString("date"));
					actComments.add(comment);
				}
			} catch (JSONException e) {
				String errMsg = "获取活动列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return actComments;
	}

	/**
	 * 发表活动评论
	 * 
	 * @param shopActivityId
	 * @param userId
	 * @param comment
	 */
	public static void doCommentShopActivity(int shopActivityId, int userId,
			String comment) {
		// TODO 暂时不做
	}

	/**
	 * 获取关注商家列表
	 * 
	 * @param userId
	 * @return
	 * @throws SVException
	 */
	public static List<Shop> fetchFollowedShopList(int userId, String search,
			int limitStart, int limit) throws SVException {
		List<Shop> shops = new ArrayList<Shop>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=list_concern_shops" + "&user=" + userId + "&search="
				+ UtilTools.encodeURL(search) + "&limitstart=" + limitStart
				+ "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取关注商家列表:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取关注商家列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject jsonObject = bean.getData().optJSONObject(i);
					Shop shop = new Shop();
					shop.setId(jsonObject.getInt("shop_id"));
					shop.setName(jsonObject.getString("shop_name"));
					shop.setCategoryId(jsonObject.optInt("category_id"));
					// shop.setCategoryName(jsonObject.optString("category_name"));
					shop.setLogo(jsonObject.optString("shop_logo"));
					shop.setAvgConsumption(jsonObject
							.getDouble("avg_consumption"));
					shop.setRating(jsonObject.optDouble("rating"));
					shop.setDistance(jsonObject.optDouble("distance"));
					shop.setServices(jsonObject.optString("services"));
					shop.setPhone(jsonObject.optString("telephone"));
					shop.setCategoryName(jsonObject.optString("category_name"));
					shop.setHasCoupon(jsonObject.optBoolean("is_coupon", false));
					ShopAddress address = new ShopAddress();
					address.setAreaCode(jsonObject.optString("region_id"));
					address.setAreaName(jsonObject.optString("region_name"));
					address.setAddress1(jsonObject.optString("address"));
					shop.setAddress(address);
					shops.add(shop);
				}
			} catch (JSONException e) {
				String errMsg = "关注商家列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shops;
	}

	/**
	 * 关注商家
	 * 
	 * @param userId
	 * @param shopId
	 * @throws SVException
	 */
	public static void doFollowShop(int userId, int shopId) throws SVException {
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=concern_shop" + "&user=" + userId + "&shop=" + shopId
				+ "&action=add";
		HashMap<String, String> headers = new HashMap<String, String>();
		try {
			Log.d(TAG, "关注商家");
			getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.d(TAG, "关注商家发生错误");
			throw e;
		}
	}

	/**
	 * 评论商家
	 * 
	 * @param comment
	 * @throws SVException
	 */
	public static void doCommentShop(Comment comment) throws SVException {
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=set_shop_pl" + "&shop=" + comment.getShop().getId()
				+ "&uid=" + comment.getUser().getId() + "&uname="
				+ comment.getUser().getUserName() + "&comment="
				+ comment.getContent() + "&title=" + comment.getTitle()
				+ "&message=" + comment.getContent() + "&rating="
				+ new Float(comment.getRating()).intValue() + "&rate_kouwei="
				+ new Float(comment.getRating_taste()).intValue()
				+ "&rate_huanjing="
				+ new Float(comment.getRating_env()).intValue() + "&rate_fuwu="
				+ new Float(comment.getRating_service()).intValue()
				+ "&people=" + comment.getPeople() + "&cost="
				+ new Float(comment.getCost()).intValue();
		HashMap<String, String> headers = new HashMap<String, String>();
		try {
			Log.d(TAG, "评论商家:" + url);
			getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.d(TAG, "评论商家发生错误");
			throw e;
		}

	}

	/**
	 * 获取商家评论列表
	 * 
	 * @param shopId
	 * @param limitStart
	 * @param limit
	 * @return
	 * @throws SVException
	 */
	public static List<Comment> fetchShopCommentList(int shopId,
			int limitStart, int limit) throws SVException {
		List<Comment> shopComments = new ArrayList<Comment>();
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=get_shop_pl" + "&shop=" + shopId + "&limitstart="
				+ limitStart + "&limit=" + limit;
		HashMap<String, String> headers = new HashMap<String, String>();
		ResponseResultBean bean = null;
		try {
			Log.d(TAG, "获取商家评论列表:" + url);
			bean = getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.e(TAG, "获取商家评论列表错误");
			throw e;
		}
		if (bean != null
				&& bean.getStatus() == ResultStatusEnum.SUCCESS.getCode()
				&& bean.getData() != null) {
			try {
				int size = bean.getData().length();
				for (int i = 0; i < size; i++) {
					JSONObject object = bean.getData().getJSONObject(i);
					Comment comment = new Comment();
					comment.setId(object.getInt("tid"));
					Shop shop = new Shop();
					shop.setId(object.getInt("shop_id"));
					comment.setShop(shop);
					User user = new User();
					user.setId(object.getInt("uid"));
					user.setUserName(object.optString("username"));
					user.setPhoto(object.optString("user_photo"));
					comment.setUser(user);
					comment.setTitle(object.optString("title"));
					comment.setContent(object.optString("comment"));
					comment.setDate(object.optString("date"));
					comment.setRating(object.optInt("rating"));
					comment.setRating_taste(object.optInt("rate_kouwei"));
					comment.setRating_env(object.optInt("rate_huanjing"));
					comment.setRating_service(object.optInt("rate_fuwu"));
					comment.setPeople(object.optInt("people"));
					comment.setCost(object.optInt("totalmonney"));
					shopComments.add(comment);
				}
			} catch (JSONException e) {
				String errMsg = "商家评论列表获取变量值错误";
				Log.e(TAG, errMsg, e);
				throw new SVException(ResultStatusEnum.FAILED.getCode(),
						errMsg, e);
			}
		}
		return shopComments;
	}

	/**
	 * 提交反馈意见
	 * 
	 * @param userId
	 * @param systemInfo
	 * @param feedback
	 * @throws SVException
	 */
	public static void doSubmitFeedback(long userId, String systemInfo,
			String feedback) throws SVException {
		String url = ServiceUrls.BASE_URL + ServiceUrls.REQUEST_URL
				+ "&type=set_feedback" + "&uid=" + userId + "&feedback="
				+ UtilTools.encodeURL(feedback);
		HashMap<String, String> headers = new HashMap<String, String>();
		try {
			Log.d(TAG, "提交反馈意见");
			getHttpConnection().getJSONBean(url, headers);
		} catch (SVException e) {
			Log.d(TAG, "提交反馈意见发生错误");
			throw e;
		}
	}
}
